Skip to content

Fix: serialize allowed_signature_methods correctly as JSON array#15

Merged
genaromadrid merged 4 commits intomasterfrom
fix/serialize-allowed-signature-methods
Apr 22, 2026
Merged

Fix: serialize allowed_signature_methods correctly as JSON array#15
genaromadrid merged 4 commits intomasterfrom
fix/serialize-allowed-signature-methods

Conversation

@rh0mb
Copy link
Copy Markdown
Contributor

@rh0mb rh0mb commented Jul 22, 2025

This PR fixes an issue where the SDK was incorrectly sending allowed_signature_methods as a Python string instead of a JSON array, causing a 500 Internal Server Error when using mixed signature types like FEA and FESCV.

What’s changed

  • In the Document.create() method, the allowed_signature_methods field is now properly serialized using json.dumps() before being sent in the form data.

Why

The Mifiel API expects allowed_signature_methods to be a JSON array (e.g. ["FEA"]), not a Python string like "['FEA']" or "FEA,FESCV". The previous version of the SDK unintentionally broke this compatibility when posting multipart/form-data requests.

Summary by CodeRabbit

  • Refactor
    • Improved internal handling of signatory field data formatting in document creation requests.

@genaromadrid
Copy link
Copy Markdown
Member

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 22, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 22, 2026

Warning

Rate limit exceeded

@genaromadrid has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 32 minutes and 9 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 32 minutes and 9 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b09cd790-436f-43dc-b329-98caa94096bb

📥 Commits

Reviewing files that changed from the base of the PR and between 5d36fca and 2bb58db.

📒 Files selected for processing (1)
  • mifiel/document.py
📝 Walkthrough

Walkthrough

The Document.create method's request payload construction changed from updating a dictionary with flattened signatory keys to building a list of tuples. This introduces explicit handling for array-type fields like allowed_signature_methods, which now emit repeated-array style parameters.

Changes

Cohort / File(s) Summary
Request Payload Serialization
mifiel/document.py
Modified signatory field serialization in Document.create from dict-based flattening to tuple list building, with special handling for repeated array parameters like allowed_signature_methods[].

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A rabbit hops with glee today,
As signatories find a better way—
From flattened keys to tuple pairs,
Arrays now get special cares,
The payload dances, crisp and neat! 📬

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: fixing the serialization of allowed_signature_methods as a JSON array, which directly addresses the core issue documented in the PR objectives.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/serialize-allowed-signature-methods

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
mifiel/document.py (1)

43-70: ⚠️ Potential issue | 🔴 Critical

Fix the mixed dict/tuple-list payload construction.

Line 43 leaves data as a dict, but lines 48 and 52 call data.append(...); Document.create() will raise AttributeError before sending the request. Keep scalar kwargs in a dict, collect repeated form fields separately, then convert to a list of tuples before calling process_request.

Proposed fix
    data = kwargs.copy()
+   viewers = data.pop('viewers', None)
+   form_data = []
    for index, item in enumerate(signatories):
      for key, val in item.items():
        if key == 'allowed_signature_methods' and isinstance(val, list):
          for method in val:
-           data.append(
+           form_data.append(
              (f'signatories[{index}][{key}][]', method)
            )
        else:
-           data.append(
+           form_data.append(
              (f'signatories[{index}][{key}]', val)
            )
 
-   if 'viewers' in data:
-     viewers = data.pop('viewers')
+   if viewers is not None:
      for index, item in enumerate(viewers):
        for key, val in item.items():
-         data.update(
-           {'viewers[' + str(index) + '][' + str(key) + ']': val}
+         form_data.append(
+           (f'viewers[{index}][{key}]', val)
          )
 
    if 'callback_url' in kwargs: data['callback_url'] = kwargs.get('callback_url')
    if file:
      mimetype = mimetypes.guess_type(file)[0]
      _file = open(file, 'rb')
      file = {'file': (basename(_file.name), _file, mimetype)}
    if dhash:
      data['original_hash'] = data.pop('dhash')
+   data = list(data.items()) + form_data
 
    doc = Document(client)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@mifiel/document.py` around lines 43 - 70, The payload mixes a dict and list
operations causing AttributeError; in the function building the request payload
(in mifiel/document.py around the signatories/viewers handling used by
Document.create()), keep scalar fields in a dict (e.g., data_dict) and
accumulate repeated form fields (signatories' allowed_signature_methods and
per-signatory entries, viewers entries) into a separate list of tuples (e.g.,
form_items); when done merge them by extending form_items with dict items
converted to (key,value) tuples and use that list for process_request; also
ensure file handling and dhash -> original_hash mapping write into the dict/form
appropriately and that callback_url is set on the dict before final conversion.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@mifiel/document.py`:
- Around line 43-70: The payload mixes a dict and list operations causing
AttributeError; in the function building the request payload (in
mifiel/document.py around the signatories/viewers handling used by
Document.create()), keep scalar fields in a dict (e.g., data_dict) and
accumulate repeated form fields (signatories' allowed_signature_methods and
per-signatory entries, viewers entries) into a separate list of tuples (e.g.,
form_items); when done merge them by extending form_items with dict items
converted to (key,value) tuples and use that list for process_request; also
ensure file handling and dhash -> original_hash mapping write into the dict/form
appropriately and that callback_url is set on the dict before final conversion.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: df88e373-a625-49c7-8272-3912ca89ab6e

📥 Commits

Reviewing files that changed from the base of the PR and between ea8e822 and 5d36fca.

📒 Files selected for processing (1)
  • mifiel/document.py

rh0mb added 3 commits April 22, 2026 10:29
This PR fixes an issue where the SDK was incorrectly sending `allowed_signature_methods` as a Python string instead of a JSON array, causing a 500 Internal Server Error when using mixed signature types like `FEA` and `FESCV`.

### What’s changed
- In the `Document.create()` method, the `allowed_signature_methods` field is now properly serialized using `json.dumps()` before being sent in the form data.

### Why
The Mifiel API expects `allowed_signature_methods` to be a JSON array (e.g. `["FEA"]`), not a Python string like `"['FEA']"` or `"FEA,FESCV"`. The previous version of the SDK unintentionally broke this compatibility when posting multipart/form-data requests.
…part/form-data

Previously, allowed_signature_methods was being serialized either as a plain string or using indexed keys (e.g., [0], [1]), which resulted in incorrect array parsing by the Mifiel API backend.

This commit updates the serialization to use the `[]` syntax:
  signatories[0][allowed_signature_methods][]=FEA
  signatories[0][allowed_signature_methods][]=FESCV

This is a widely supported format for arrays in multipart/form-data and ensures compatibility with the backend’s expected structure.

Also removes the use of json.dumps, which was turning arrays into escaped strings instead of sending them as proper arrays.
Replaced internal data structure with a list of tuples to correctly handle
multiple allowed_signature_methods for each signer in multipart/form-data.

This change ensures repeated keys are preserved, allowing the backend
to receive arrays like:

  signatories[0][allowed_signature_methods][]=FEA
  signatories[0][allowed_signature_methods][]=FESCV

instead of silently overwriting values when using a dict.
Document.create mistakenly called dict.append when serializing
signatories. Store scalar signatory fields on the dict, collect
allowed_signature_methods as repeated bracket keys, then convert
to a list of tuples for requests when needed. Apply callback_url and
original_hash (dhash) before conversion so dict operations stay valid.

Co-authored-by: Genaro Madrid <genaromadrid@users.noreply.github.com>
@genaromadrid genaromadrid merged commit a45d6a7 into master Apr 22, 2026
2 checks passed
@genaromadrid genaromadrid deleted the fix/serialize-allowed-signature-methods branch April 22, 2026 16:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants